/*
* demo.c
*
* Created: 19.04.2014 19:28:29
*  Author: markus.hufschmid
*/
#include "defines.h"
#include "Deco.h"
#include "globals.h"
#include "dive.h"
#include "demo.h"
#include "OLED.h"
#include <asf.h>
#include <math.h>

void demo(void){
	float p_no_deco[16];
	deco_info_t info;
	float h = 0.0;
	float p_ambient;
	int sec = 0, min = 0;
	float d_h;
	static float d_h_filtered = 0.0;
	float old_h = 0;
	int16_t vario_height;
	float depth = 0.0;
	
	temperature = 170;
	prepare_dive_screen();
	print_string_zoomed("DEMO",29,5,YELLOW, BLACK, 2);
	reset_p_tissues(0.932);
	compute_p_no_deco(0.932, p_no_deco);

	while (min < 20){
		shutdown_timer = 0;
		sec++;
		if (sec == 60){
			sec = 0;
			min++;
		}
		if (min == 1){
			h = 50.0;
		}
		if (min >= 10){
			h = h - 10.0/60.0;
			if (h < (float)info.deco_depth_meters){
				h = (float)info.deco_depth_meters;
			}
		}
		p_ambient = h/10.0 + 0.932;
		depth = 10.0*h;
		d_h = h - old_h;
		old_h = h;
		d_h_filtered = d_h_filtered + d_h;
		d_h_filtered = d_h_filtered/2.0;
		vario_height = (int)round(d_h_filtered*120.0);
		
		update_tissues(p_ambient, percentage_N2, delta_time);
		info = compute_deco_information(p_ambient, 0.932, p_no_deco, 3.0, percentage_N2);
		update_dive_screen(info, depth, min, temperature/10, vario_height);
	}
}
